package com.caiheng.api.controller.platform;

import cn.hutool.json.JSONObject;
import com.caiheng.api.constant.ResponseCode;
import com.caiheng.api.service.platfom.ParameterService;
import com.caiheng.api.util.GsonResultBean;
import com.caiheng.api.util.Tools;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *@Author: ZhouWei
 *@Description:  通知公告类 相关接口
 *@Date 2018-05-10
 */
@Component
@RestController
@RequestMapping("/parameter")//url:模块/资源/{}/细分
public class ParameterController extends BaseController {

    @Resource
    private ParameterService parameterService;

    /**
     *  重新获取配置信息
     * @param
     * @throws Exception
     */
    @GetMapping(value="/reset/{id}")
    public JSONObject detail(@PathVariable(value = "id",required = false) Integer id) throws Exception{
        JSONObject result = null;
        try{
            if(id == null){
                id = 1;
            }
            parameterService.resetParameter(id);

            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功"),true,false);
        }catch (Exception e){
            e.printStackTrace();
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            System.out.println(e.getMessage());
            logger.error(e.getMessage(), e);
        }
        return result;
    }
}
